package com.firemoss.ui.blanket
{
	import flash.display.DisplayObjectContainer;
	
	import mx.core.UIComponent;
	import mx.managers.ISystemManager;

	/**
	 * Default implementation of IBlanketDisplayObjectContainerLocator used within
	 * Blanket.  (Ab)uses the SystemManager of a given component to shove
	 * a Blanket-specific UIComponent subclass into the first position in its 
	 * popup rendering "layer" if it doesn't exist.  Once it exists,
	 * we return it as the DisplayObjectContainer to use.
	 */
	public class PopUpLayerBlanketDisplayObjectContainerLocator implements IBlanketDisplayObjectContainerLocator
	{
		
		public function PopUpLayerBlanketDisplayObjectContainerLocator()
		{
			super()
		}

		public function findDisplayObjectContainer(args:Object=null) : DisplayObjectContainer
		{
			if ( !args.hasOwnProperty( "target" ) || !( args.target is UIComponent ) )
			{
				throw new Error("For DefaultBlanketDisplayObjectContainerLocator's findDisplayObjectContainer(), pass \"target\" as a member of the args structure, and make sure it's non-null and a UIComponent.")
			}
			
			var target : UIComponent = args.target as UIComponent
			
			// Get its system manager and make sure its first "tooltip" child is really our shoved-in container
			var sysManager : ISystemManager = target.systemManager
			
			if ( sysManager is DisplayObjectContainer )
			{
				return sysManager as DisplayObjectContainer
			}
			else
			{
				return null
			}
		}
		
	}
}